<template>
  <section class="main">
      <input id="toggle-all" class="toggle-all" type="checkbox" v-model="ischekall"/>
      <label for="toggle-all" @click="all">Mark all as complete</label>
      <ul class="todo-list">
        <!-- 当任务已完成，可以给 li 加上 completed 类，会让元素加上删除线 -->
        <li :class="{ completed:item.isDone }" v-for="(item) in list" :key="item.id">
          <div class="view">
            <input class="toggle" type="checkbox" :checked="item.isDone" @change="ischange(item)"/>
            <label>{{ item.title }}</label>
            <button class="destroy" @click="del(item.id)"></button>
          </div>
        </li>
    
      </ul>
      <!-- <h1>我是子组件{{ value }}</h1> -->
      <!-- <button @click="change1">修改msg属性</button> -->
    </section>
</template>

<script>
import { mapState,mapActions } from 'vuex'
export default {

  props: ['list','type','value'],
  methods: {
    ...mapActions('list', ['dellist']),
    ...mapActions('list',['isall','tick','getlist']),
    change1() {
      this.$emit('input','234')
    },
    ischange(item) {
      this.tick(item)
      console.log(item);
    },
    del(id) {
      this.dellist(id)
     
    },
    all() {
      this.isall()
    }
  },
  computed: {
    ...mapState('list',['todolist']),
    
    ischekall: {
      get() {
        return this.list.every(x => {
          x.isDone
        })
      },
      set(val) {
        this.$emit('ischekall',val)
      }
    },
    // isshow() {
    //   if (this.type === 'active') {
    //    return this.list.filter(x => {
    //       return !x.isDone
    //     })
    //   } else if (this.type === 'completed') {
    //    return this.list.filter(x => {
    //       return x.isDone
    //     })
    //   }
    //   return this.list
    // },
    
  }
}
</script>

<style>

</style>